package com.fourfinance.custom;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

import com.fourfinance.util.LenderConstants;

public class CustomSerializer extends JsonSerializer<Object> {

	@Override
	public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
		
		if(value instanceof Long){
			jgen.writeString(String.valueOf(value));
		} else if(value instanceof Float){
			jgen.writeString(String.valueOf(value));
		} else if(value instanceof Date){
	        SimpleDateFormat formatter = new SimpleDateFormat(LenderConstants.DATE_FORMAT);
	        String formattedDate = formatter.format(value);
	        jgen.writeString(formattedDate);
		}
		
	}

}
